'use client'

import { SignType, useSignContext } from '@/hooks/auth/use-sign'
import useIsLogged from '@/hooks/common/use-loggin'
import { useUser } from '@clerk/nextjs'
import { useState } from 'react'

export const useRootContext = () => {
  const [user, changeUser] = useState()
  const userInfo = useUser()
  const isLogged = useIsLogged()

  const signContext = useSignContext()

  const openClerk = (type: SignType, callback: any) => {
    if (!isLogged) {
      signContext?.[type]?.()
    } else {
      callback()
    }
  }

  return {
    user,
    changeUser,
    userInfo: userInfo.user,
    isSignedIn: userInfo.isSignedIn,
    isLoaded: userInfo.isLoaded,
    ...signContext,
    openClerk
  }
}
